<template>
  <div style="margin-right: 10px; background: #fff; padding-top: 10px">
    <div style="width: 100%; height: 100%"
         class="chart_hidde"
         ref="chart"></div>
  </div>
</template>

<script>
var myChartKWH;
export default {
  data() {
    return {
      resizeTimer1: null
    };
  },
  mounted() {
    window.addEventListener("resize", function () {
      if (this.resizeTimer1) clearTimeout(this.resizeTimer1);
      this.resizeTimer1 = setTimeout(function () {
        myChartKWH.resize();
      }, 300);
    });
    this.setOpt()
  },
  methods: {
    setOpt(data) {
      const that = this;
      this.$nextTick(() => {
        myChartKWH = this.$echarts.init(this.$refs.chart);
        const colorList = ["#0E7CE2", "#FF8352", "#E271DE"];
        const option = {
          color: colorList,
          tooltip: {
            trigger: "item",
            formatter: "{a} <br/>{b}: {c} ({d}%)",
          },

          title: {
            text: "峰谷平电量类比环图",
            left: "center",
          },
          legend: {
            orient: "vertical",
            x: "right",
            right: "10%",
            top: "35%",
            data: ["峰时电量", "谷时电量", "平时电量"],
          },
          series: [
            {
              name: "峰谷平电量类比环图",
              type: "pie",
              radius: ["40%", "55%"],

              data: [
                {
                  value: data ? data["峰时电量"] : 0,
                  name: "峰时电量",
                  selected: true,
                  itemStyle: {
                    normal: {
                      borderColor: colorList[0],
                      shadowColor: colorList[0],
                      borderWidth: 3,
                      shadowBlur: 20,
                    },
                  },
                  label: {
                    // 单独显示该数据项
                    show: true,
                    formatter: (v) => {
                      return `${v.value}Kw·h`;
                    },
                    position: "outer",
                    fontSize: 15,
                  },
                },
                {
                  value: data ? data["谷时电量"] : 0,
                  name: "谷时电量",
                  itemStyle: {
                    normal: {
                      borderColor: colorList[1],
                      shadowColor: colorList[1],
                      borderWidth: 3,
                      shadowBlur: 20,
                    },
                  },
                  label: {
                    // 单独显示该数据项
                    show: true,
                    formatter: (v) => {
                      return `${v.value}Kw·h`;
                    },
                    position: "outer",
                    fontSize: 15,
                  },
                },
                {
                  value: data ? data["平时电量"] : 0,
                  name: "平时电量",
                  itemStyle: {
                    normal: {
                      borderColor: colorList[2],
                      shadowColor: colorList[2],
                      borderWidth: 3,
                      shadowBlur: 20,
                    },
                  },
                  label: {
                    // 单独显示该数据项
                    show: true,
                    formatter: (v) => {
                      return `${v.value}Kw·h`;
                    },
                    position: "outer",
                    fontSize: 15,
                  },
                },
              ],
            },
          ],
        };

        myChartKWH.setOption(option);
      });
    }
  },
};
</script>

<style lang="scss" scoped>
.chart_hidde {
  overflow: hidden !important;
}
.ener_content {
  padding: 0 50px;
}
</style>